//
//  TABAnimatedDarkModeSwitchImpl.m
//  AnimatedDemo
//
//  Created by tigerAndBull on 2020/5/5.
//  Copyright © 2020 tigerAndBull. All rights reserved.
//

#import "TABAnimatedDarkModeImpl.h"

#import "TABAnimatedProduction.h"
#import "TABComponentLayer.h"
#import "TABViewAnimated.h"

#import "TABAnimatedDarkModeInterface.h"

@implementation TABAnimatedDarkModeImpl

- (void)traitCollectionDidChange:(UITraitCollection *)traitCollection
                     tabAnimated:(TABViewAnimated *)tabAnimated
                 backgroundLayer:(TABComponentLayer *)backgroundLayer
                          layers:(NSArray <TABComponentLayer *> *)layers {
    
    UIColor *animatedBackgroundColor = nil;
    UIColor *animatedColor = nil;
    
//    if (LLDarkManager.isDarkMode) {
//        animatedBackgroundColor = tabAnimated.darkAnimatedBackgroundColor;
//        animatedColor = tabAnimated.darkAnimatedColor;
//    } else {
        animatedBackgroundColor = tabAnimated.animatedBackgroundColor;
        animatedColor = tabAnimated.animatedColor;
//    }
    
    backgroundLayer.backgroundColor = animatedBackgroundColor.CGColor;
    for (TABComponentLayer *layer in layers) {
        if (layer.numberOflines > 0) {
            for (TABComponentLayer *sub in layer.lineLayers) {
                sub.backgroundColor = animatedColor.CGColor;
            }
        }else {
            layer.backgroundColor = animatedColor.CGColor;
        }
        if (layer.contents && layer.placeholderName && layer.placeholderName.length > 0) {
            layer.contents = (id)[UIImage imageNamed:layer.placeholderName].CGImage;
        }
    }
}

@end
